#include <iostream>
using namespace std;
const int N = 100;
// a满分值 b 正确答案 c 学生解答
int a[N+5];
int b[N+5];
int c[N+5][N+5];
int d[N+5];
int main(){
    int n, m;
    cin >> n >> m;
    //input 题目个数
    for(int i = 0; i < m; ++i){
        cin >> a[i];
    }
    //input 正确答案
    for(int i = 0; i < m; ++i){
        cin >> b[i];
    }
    //学生答题
    for(int i = 0; i < n; ++i){
        int rel = 0;
        for(int j = 0; j < m; ++j){
            cin >> c[i][j];
            if(c[i][j] == b[j]){
                rel += a[j];
            }
        }
        d[i] = rel;
        rel = 0;
    }
    for(int i = 0; i < n; ++i){
        cout << d[i] <<endl;
    }
    return 0;
}